package wemai;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.ElementNotVisibleException;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.internal.seleniumemulation.KeyEvent;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class m_qqcom extends WebMail {

	public void send(String uid, String password, String to, String subject, String content) throws Exception {

		try {
			String url = "https://mail.qq.com/cgi-bin/loginpage?lang=cn";
			dr.get(url);
			
			
			/*try{
				dr.findElement(By.name("uin")).sendKeys(uid);
			}catch(ElementNotVisibleException enve){
				executeScript("pt.switchPage();");
				sleep(2000);
			}*/
			
			dr.findElement(By.name("uin")).sendKeys(uid);
			sleep(2000);
			dr.findElement(By.name("p")).sendKeys(password);
			sleep(2000);
			dr.findElement(By.id("btlogin")).click();

			waitWebElement(By.linkText("写信")).click();

			waitWebElement(By.name("mainFrame"));
			dr.switchTo().frame("mainFrame");

			waitWebElement(By.id("otherComposeOptionBtn"));

			content = StringUtils.remove(content, '\r');
			content = StringUtils.remove(content, '\n');

			content = StringEscapeUtils.escapeEcmaScript(content);

			executeScript("  document.getElementById('content').value='" + content + "'   ");

			executeScript("  document.getElementById('to').value='" + to + "'   ");

			executeScript("  document.getElementById('subject').value='" + subject + "'   ");

			executeScript("  document.getElementById('frm').submit()   ");

		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			sleep(6000);
			dr.quit();
		}
	}

	public static void main(String[] args) {
		try {
			String uid = "aqqtmac16888";
			String password = "321654987po";
			String to = "o21x@qq.com";
			String subject = "图片频道十分钟告";
			String content = "dddddddddddddddd";

			new m_qqcom().send(uid, password, to, subject, content);
			Thread.sleep(60000);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
